<template>
<div class="home-container">
  <div class="todo-list">
    <div class="todo-list-text">
        <h1 class="todo">待办事项</h1>
      <p class="p-todo">物资供应签字列表</p>
    </div>
  <img class="icon" src="../public/icon2x.png" >
  </div>
  <!--此处插入列表展示-->
  <todo-list/>
  <!--根据用户类型显示不同的组件-->
  <component :is="currentTabComponent"></component>
</div>
</template>
<script>
import TabBar from "@/components/TabBar.vue"
import TabBarFrom from "@/components/TabBarFrom.vue"
import todoList from "@/components/todoList.vue"
import { getCurrentUser } from './js/login'

export default {
  data(){
    return{
      currentUser: null,
      isAdmin: false
    }
  },
  computed: {
    currentTabComponent() {
      // 如果是admin1账号，使用TabBar，否则使用TabBarForm
      return this.isAdmin ? 'TabBar' : 'TabBarForm'
    }
  },
  methods:{
    checkUserRole() {
      this.currentUser = getCurrentUser()
      if (this.currentUser && this.currentUser.username === 'admin') {
        this.isAdmin = true
      } else {
        this.isAdmin = false
      }
      console.log('当前用户:', this.currentUser.username, '是管理员:', this.isAdmin)
    }
  },
  created() {
    // 在组件创建时检查用户角色
    this.checkUserRole()
  },
  components:{
    TabBar,
    TabBarForm: TabBarFrom,
    todoList
  }
}
</script>
<style>
.home-container{
  width: 100%;
  height: 80vh;
  background-image: url("../public/bg2x.png");
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
}
.todo-list{
  display: flex;
  align-items: start;
  margin-right: 200px;
  margin-top: 40px;
  margin-bottom: 40px;
}
.todo-list-text{
  display: flex;
  flex-direction: column;
}
.todo{
  color: #333;
  margin: 2px 0;
  font-weight: bold;
  font-style: italic;
}
.p-todo{
  font-size: 12px;
  color: #666;
  margin: 2px 0;
  font-style: italic;
}
.icon{
  position: fixed;
  top: 50px;
  right: 50px;
  width: 140px;
  height: 140px;
}
</style>